import Taro from "@tarojs/taro";
import { useCallback, useRef } from "react";

/**
 * 获取设备一些尺寸
 */
export function useDeviceRect() {
  const { current } = useRef(Taro.getSystemInfoSync());
  const height = current.windowHeight;
  const width = current.windowWidth;
  const statusBarHeight = current.statusBarHeight ?? 0;
  const safeAreaBottomHeight = height - (current.safeArea?.bottom ?? 0);
  const navbarHeight = 40;

  const scrollHeight = useCallback(
    (areaHeight: number) => {
      return (
        height -
        (areaHeight + statusBarHeight + safeAreaBottomHeight + navbarHeight)
      );
    },
    [height, safeAreaBottomHeight, statusBarHeight]
  );

  return {
    height,
    width,
    statusBarHeight,
    safeAreaBottomHeight,
    navbarHeight,
    scrollHeight,
  };
}
